/*
 * @Author: shanghongyun 2879455630@qq.com
 * @Date: 2025-05-28 13:42:41
 * @LastEditors: shanghongyun 2879455630@qq.com
 * @LastEditTime: 2025-07-08 09:30:15
 * @FilePath: \A05\Dev\systick.c
 * @Description: systick源文件
 */

#include "systick.h"
#include "dpm32m0xx_rcc.h"

uint32_t gCurrent_tick = 0;
 

/**
 * @description: 滴答定时器配置
 * @return {*}
 */
void Systick_Init(void)
{
    /* 配置SysTick为1ms中断一次 */
    if (SysTick_Config(SYS_Frequency / SYSTICK_FREQUE))
    {
        /* 如果配置失败，进入死循环 */
        while (1);
    }
    
    /* 配置SysTick中断优先级 */
    NVIC_SetPriority(SysTick_IRQn, 0x01);
}




/**
 * @description: 获取当前tick
 * @return {*}
 */
uint32_t Get_system_Timestamp(void)
{
    return gCurrent_tick;
}

/**
 * @description: 获取时间间隙
 * @param {uint32_t} start_tick
 * @param {uint32_t} end_tick
 * @return {*}
 */
uint32_t Get_Time_gap(uint32_t start_tick, uint32_t end_tick)

{
    if (end_tick >= start_tick) {
        return (end_tick - start_tick);
    } else {
        /* 处理计数器溢出的情况 */
        return (0xFFFFFFFF - start_tick + end_tick + 1);
    }
}

extern ADC_InitTypeStruct ADC_InitStruct;
extern uint8_t gADCconvertPos;
extern uint8_t gADCconvertSeq[];
#include "charger.h"
/**
 * @description: 滴答定时器中断处理函数
 * @return {*}
 */
void SysTick_Handler(void){
    gCurrent_tick++;
    Short_circuit_detect(&charger.battery_L);
    Short_circuit_detect(&charger.battery_R);
    // ADC_InitStruct.SoftTrigChannel = gADCconvertSeq[gADCconvertPos];
    // ADC_Init(ADC0, &ADC_InitStruct);

    // ADC_StartConversion(ADC0); // 重新开始转换
}



